/*
 *================================================================================
 *	Plik: f_ld4.c
 *	Created on: May 28, 2011
 *--------------------------------------------------------------------------------
 *	Autorzy: Piotr Zdunek, Mateusz Słowikowski, Krzysztof Wiąckowski
 *	Projekt: Model mikrokontrolera AVR
 *	Kompilator: avr-gcc-4.3.5
 *	Doc: doxygen 1.4.3
 *--------------------------------------------------------------------------------
 *	Zawiera: Funkcję LDD - wersję z przeniesieniem (with displacement);
 *--------------------------------------------------------------------------------
 *	Komentarze:
 *================================================================================
 */

#include "types.h"
#include "mem_abs.h"

void F_LDDY() {

#ifndef  DEBUG_MODE
	printf("Function LDDY.");
#endif
	//Resolve variable value form opcode
	uint8_t Rd = (((getMEMC(getPC()) & 0x0FF0) & 0b00011111)) >> 4;
	uint8_t Rd_val = GetRegisterFromDataSpace(GetYRegister());
	uint8_t k = 0;

	k = ((getMEMC(getPC()) & 0x000F) & 0b0111);
	k = k | ((((getMEMC(getPC()) & 0x0F00)) >> 8) & 0b1100) << 1;
	k = k | (((getMEMC(getPC()) & 0xF000) >> 12) & 0b0010) << 4;

	displaceY(k);
	setRegister(Rd,Rd_val);
	incPC();



}

